home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
dirut
/
attribcr.zip
/
ATTRIBCR.ASM
next >
Wrap
Assembly Source File
|
1986-02-21
|
16KB
|
533 lines
PAGE 62,132
TITLE ATTRIB - a program to alter file attributes
NAME ATTRIB
; attrib.asm 3 Feb 86 Craig Milo Rogers at USC/ISI
; I received this program from net.sources in response to an
; inquiry I sent to Info-IBMPC. Unfortunately, the program fell
; short of my goals: it didn't support the Archive bit. However,
; the program was nicely structured and readily extended.
;
; I also made a couple of other minor changes. I changed the
; command parser to make '.*' the default when the file name extension
; is not specified. I changed the command parser to accept ";" as a
; delimiter. I changed the command parser to accept multiple
; attributes. In the case of incompatible attributes the last one
; wins.
;
; The user should be aware that there are some other
; differences between this program and the DOS 3.10 ATTRIB command.
; The DOS ATTRIB command lists the entire drive and path when
; listing files, while this program lists only as much of the
; path as the user specified.
;
; This program was written by Bob Eager, Herne Bay, England.
; It is placed in the public domain. No part of this program
; may be copied and sold for gain.
;
; There isn't really much in the way of documentation. ATTRIB
; works like the DOS 3 command of the same name (except that it
; is a lot smaller and also DOES a lot MORE!)
;
; For those unfamiliar with that:
; ATTRIB filename - reports file attributes as single letters
; (H, S, R, A)
; ATTRIB +x filename - sets the x attribute (H, S, R or A)
; ATTRIB -x filename - unsets the x attribute (H, S, R ar A)
;
; The filename may be a wildcard. Multiple attributes may be specified.
;
; Inverse attributes are provided as a friendly touch:
;
; Hidden <==> Visible
; System <==> User
; Read <==> Write
; Archive <==> Backed-up
;
; So +R is the same as -W, etc.
;
; Enjoy!
;
.SALL
;
; Values for exit status:
; 0 - Success
; 1 - Parameter too long
; 2 - Incorrect DOS version
; 3 - File does not exist
; 4 - Invalid attribute letter
;
; Constants
;
TAB EQU 09H ; Tabulate
LF EQU 0AH ; Linefeed
CR EQU 0DH ; Carriage return
PTHSEP1 EQU '\' ; Normal path separator
PTHSEP2 EQU '/' ; Alternate path separator
;
STDOUT EQU 1 ; Standard output handle
STDERR EQU 2 ; Standard error handle
MAXFNAM EQU 63 ; Maximum length of filename
;
; Macro definitions
;
MSG MACRO X,Y ;; define a message
MES&X DB Y
LMES&X EQU $-MES&X
ENDM
;
$MSG MACRO X ;; display a message on standard error
MOV BX,STDERR ;; file handle
MOV DX,OFFSET MES&X ;; location of message
MOV CX,LMES&X ;; length of message
MOV AH,40H ;; write function
INT 21H
ENDM
;
CSEG SEGMENT
;
ORG 100H
;
ASSUME CS:CSEG,DS:CSEG,ES:CSEG,SS:CSEG
;
MAIN PROC FAR
JMP MAIN10
;
SUBTTL Data areas
PAGE+
;
; Storage
;
ATT DW ? ; Mask and bits specified by parameter
FIRST DB ? ; Used for 'find first' calls
PARPTR DW ? ; Pointer to next parameter
PSIZE DW ? ; Size of path part of filename
DISP DB ?,?,?,?,' ' ; Attribute display string
LDISP EQU $-DISP ; Length of DISP
FNAME DB MAXFNAM+1 DUP (?) ; Extra byte for terminator
DTA DB 43 DUP (?) ; Alternate disk transfer area
;
; Table of attribute settings
;
; The table ATTC is a list of valid attribute letters
; The table ATTON corresponds one-to-one with ATTC for setting an attribute
; The table ATTOFF corresponds one-to-one with ATTC for clearing an attribute
; ATTON and ATTOFF use the high byte of each entry as a mask to clear
; unwanted bits, and the low byte to indicate bits to be set.
;
ATTC DB 'RWHVSUAB'
NATT EQU $-ATTC
ATTON DW 0FE01H,0FE00H,0FD02H,0FD00H,0FB04H,0FB00H,0DF20H,0DF00H
ATTOFF DW 0FE00H,0FE01H,0FD00H,0FD02H,0FB00H,0FB04H,0DF00H,0DF20H
;
CRBUF DB CR,LF
;
DW 32 DUP (?) ; Stack
STACK LABEL WORD
;
; Messages
;
MSG 1,<'Parameter too long',CR,LF>
MSG 2,<'Filename too long - '>
MSG 3,<'Incorrect DOS version',CR,LF>
MSG 4,<'No matching file found for '>
MSG 5,<'Invalid attribute letter',CR,LF>
;
SUBTTL Main code
PAGE+
;
MAIN10: MOV SP,OFFSET STACK ; set up stack
;
MOV AH,30H
INT 21H ; get DOS version
XCHG AH,AL ; make more useful form
CMP AX,0200H ; version 2 at least?
JAE MAIN20 ; j if so - OK
$MSG 3 ; "Incorrect DOS version"
MOV AL,2 ; exit status
JMP SHORT MAIN60 ; join common exit code
;
MAIN20: MOV DX,OFFSET DTA ; set alternate DTA to avoid...
MOV AH,1AH ; ...overwriting parameters
INT 21H
MOV PARPTR,81H ; start of parameter area
CALL GETFLAGS ; get any attribute flags
JC MAIN60 ; j if error (unrecognised flag)
MAIN30: CALL GETPAR ; read next parameter item
JC MAIN50 ; j if no more parameters
CALL DOTSTR ; add '.*' if needed
MOV BYTE PTR FIRST,0 ; clear 'find first' flag
MAIN40: CALL GETNAM ; get next filename
JC MAIN30 ; j if no more names
CALL DOATTR ; handle attribute
JC MAIN60 ; j if error (status in AL)
JMP MAIN40 ; see if more to do
;
MAIN50: XOR AL,AL ; zero status
;
MAIN60: MOV AH,4CH ; exit
INT 21H
MAIN ENDP
;
SUBTTL Get attribute flag from command line
PAGE
;
; This routine reads an attribute flag and its sense from the command line.
; Attribute flags start with '+' or '-' and continue with a letter.
; Possible letters are: R - read only
; W - read and write (inverse of read only)
; H - hidden
; V - visible (inverse of hidden)
; S - system
; U - user (inverse of system)
; A - archive needed
; B - backed-up (inverse of archive-needed)
;
; On entry: PARPTR points to the first byte of the parameter string
;
; On exit: PARPTR has been updated past the attribute specification if
; one was found
;
; Return is made with ATT high containing a mask to remove any unwanted bits,
; and with ATT low containing any additional bits to be set in the attributes.
; The value ATT=0FF00H is returned if no attribute flag was found, and carry
; is set if an unrecognised attribute letter was encountered.
;
GETFLAGS PROC NEAR
MOV ATT,0FF00H ; This mask leaves the attributes
; unchanged.
CLD ; autoincrement
MOV SI,PARPTR ; point to start of parameter list
GETF10: LODSB ; skip leading spaces...
CMP AL,' '
JE GETF10
CMP AL,TAB ; ...and tabs
JE GETF10
CMP AL,'+' ; valid sense?
JE GETF20 ; j if so
CMP AL,'-' ; other sense?
JE GETF20 ; j if so
GETF15: DEC SI ; Backup the parameter pointer.
MOV PARPTR,SI ; Save the pointer for later use.
CLC ; indicate success
RET ; return with carry clear
;
GETF20: MOV DL,AL ; save sense
LODSB ; get attribute letter
GETF25: CALL UPPER ; convert to upper case
MOV BX,OFFSET ATTC ; list of valid letters
MOV CX,NATT ; count of valid letters
XOR DI,DI ; pointer into letter table
GETF30: CMP AL,[BX+DI] ; found the letter?
JE GETF40 ; j if so
INC DI ; point to next possibility
LOOP GETF30 ; keep trying
$MSG 5 ; "Invalid attribute letter"
MOV AL,4 ; exit status
STC ; indicate error
RET
;
GETF40: MOV BX,OFFSET ATTON ; assume sense 'on'
CMP DL,'-'
JNE GETF50 ; j if sense 'on' required
MOV BX,OFFSET ATTOFF ; else use different table
GETF50: ADD DI,DI ; form word offset
MOV AX,[BX+DI] ; get mask and attribute word
MOV BX,ATT ; Get the previous mask.
AND BL,AH ; Clear incompatible bits.
AND AH,BH ; Merge the bits-to-keep mask.
OR AL,BL ; Merge the bits-to-set mask.
MOV ATT,AX ; Save the resultant mask.
GETF60: LODSB ; Get the next command byte.
CMP AL,' ' ; Space means end of these flags.
JE GETF10 ; Jump to look for next flags.
CMP AL,TAB ; Tab also means end of these flags.
JE GETF10 ; Jump to look for next flags.
CMP AL,CR ; CR is premature, treat it
JE GETF15 ; as the end of the flags.
CMP AL,'+' ; Plus is another set of flags.
JE GETF20 ; Go parse the flags.
CMP AL,'-' ;